package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.myapplication1.dao.UserDao;
import com.example.myapplication1.model.User;

public class ForgetActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_back;
    private Button btn_query;
    private EditText et_account;
    private EditText et_phone;

    private UserDao userDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget);

        btn_back=findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
        btn_query=findViewById(R.id.btn_query);
        btn_query.setOnClickListener(this);
        et_account=findViewById(R.id.et_account);
        et_phone=findViewById(R.id.et_phone);

        userDao =new UserDao(ForgetActivity.this);
    }

    @Override
    public void onClick(View view) {
        int id=view.getId();
        switch (id){
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_query:
                //获取输入框中内容
                String account=et_account.getText().toString();
                String phone=et_phone.getText().toString();
                if (account.trim().length()==0){
                    Toast.makeText(ForgetActivity.this,"账号不能为空",Toast.LENGTH_SHORT).show();
                    return;//中断方法
                }
                if (phone.trim().length()==0){
                    Toast.makeText(ForgetActivity.this,"手机号不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                String password=userDao.queryPasswordByAccountAndPhone(account,phone);
                if(password==null){
                    //没有找到
                    Toast.makeText(ForgetActivity.this,"该账号和手机号无法查询到相应密码",Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(ForgetActivity.this,"您的密码为： "+password,Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}